import { getData, postData, putData, deleteData } from '@/api/common/index';

const baseUserInfo = '/api/user-info';

const UserInfoUrl = {
	page: '/page',
	url: '',
	queryUserList: '/queryUserList',
	queryUserReduceInfo: '/recharge-hierarchy/page',
	exportUserReduce: '/recharge-hierarchy/export',
	queryUserIncomeInfo: '/queryUserReduceInfo',
};

export function getUserInfoPage(
	params: any,
	pageNo: number | null | undefined,
	pageSize: number | null | undefined,
): Promise<any> {
	let url =
		baseUserInfo +
		UserInfoUrl.page +
		'?pageNum=' +
		(pageNo ? pageNo : 1) +
		'&pageSize=' +
		(pageSize ? pageSize : 10);
	return postData(url, params);
}

export function getUserInfoDetail(id: number): Promise<any> {
	return getData(baseUserInfo + UserInfoUrl.url + '?id=' + id);
}

export function deleteUserInfo(ids: string): Promise<any> {
	return deleteData(baseUserInfo + UserInfoUrl.url + '?ids=' + ids);
}

export function addOrEditUserInfo(method: string, params: any): Promise<any> {
	if ('put' == method) {
		return putData(baseUserInfo + UserInfoUrl.url, params);
	} else {
		return postData(baseUserInfo + UserInfoUrl.url, params);
	}
}

// 获取用户列表
export function getUserInfoList(params: any): Promise<any> {
	let url = baseUserInfo + UserInfoUrl.queryUserList;
	return postData(url, params);
}

// 获取用户邀请人流水
export function queryUserReduceInfo(
	params: any,
	pageNo: number | null | undefined,
	pageSize: number | null | undefined,
): Promise<any> {
	let url =
		baseUserInfo +
		UserInfoUrl.queryUserReduceInfo +
		'?pageNum=' +
		(pageNo ? pageNo : 1) +
		'&pageSize=' +
		(pageSize ? pageSize : 10);
	return postData(url, params);
}

// 导出用户邀请人流水
export function exportUserReduce(params: any, response: any): Promise<any> {
	let url = baseUserInfo + UserInfoUrl.exportUserReduce;
	return postData(url, params, response);
}

// 导出用户信息
export function exportUserInfoApi(params: any): Promise<any> {
	const url = baseUserInfo + '/export-user-info';
	// 直接返回 response，包含文件流
	return postData(url, params, { responseType: 'blob' });
}

// 查询用户伞下收益
export function queryUserIncomeInfo(
	params: any,
	pageNo: number | null | undefined,
	pageSize: number | null | undefined,
): Promise<any> {
	let url =
		baseUserInfo +
		UserInfoUrl.queryUserIncomeInfo +
		'?pageNum=' +
		(pageNo ? pageNo : 1) +
		'&pageSize=' +
		(pageSize ? pageSize : 10);
	return postData(url, params);
}
